package SparkSmallPaper
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.rdd.RDD
import org.apache.log4j.{Level, Logger}
//x(0)是买家id，x(1)是商品id,x(2)是商品类别，x(3)是卖家id,x(4)是品牌id，x(5)是交易月，x(6)是交易日，x(7)是买家行为，x(8)是买家年龄段,x(9)是买家性别，x(10)是收获地址，
//该代码是实现查看各个省份的购物数量
object demo05 {
  def main(args: Array[String]): Unit = {
        val conf = new SparkConf().setMaster("local[2]").setAppName(demo01.getClass.getSimpleName)
        Logger.getLogger("org.apache.spark").setLevel(Level.OFF)
        val sc = new SparkContext(conf)
        transformationOps5(sc)
        sc.stop()
    }
  def transformationOps5(sc:SparkContext): Unit = {
        val lines = sc.textFile("file:///C:/Users/asus/Desktop/hadoop_experiment/data/user_log.csv")
        //lines.foreach(println)
        val wordsRDD = lines.map(line => line.split(","))
        
        val Provincial_purchasing_power=wordsRDD.map(w=>(w(10),w(7))).filter(w=>w._2.equals("2"))
        
        val grou1=Provincial_purchasing_power.groupByKey()

        grou1.foreach(w=>println("{value:"+w._2.size+", name:'"+w._1+"'},"))
        

    }
}